package com.newtouch.xcd.admin.wechat.handler;

import com.alibaba.dubbo.config.annotation.Reference;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author Binary Wang(https://github.com/binarywang)
 */
@Component
public class UnsubscribeHandler extends AbstractHandler {

//    @Reference
//    private CwrWechatUserService cwrWechatUserService;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService wxMpService,
                                    WxSessionManager sessionManager) {
        String openId = wxMessage.getFromUser();
        this.logger.info("取消关注用户 OPENID: " + openId);

//        // 可以更新本地数据库为取消关注状态
//        String appId = this.cwrWechatUserService.queryAppId();
//        CwrWechatUser cwrWechatUser = cwrWechatUserService.queryByOpenIdAndAppId(openId,appId);
//
//        if(null == cwrWechatUser){
//            return null;
//        }
//
//        cwrWechatUser.setSubscribe("false");
//        cwrWechatUser.setUpdatedTime(DateUtils.now());
//        this.cwrWechatUserService.saveOrUpdate(cwrWechatUser);

        return null;
    }

}
